package com.fenxiangtech.mall.service.impl;

import com.fenxiangtech.mall.service.ImageService;
import com.fenxiangtech.mall.dao.CategoryDao;
import com.fenxiangtech.mall.entity.Category;
import com.fenxiangtech.mall.entity.Image;
import com.fenxiangtech.mall.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangjiashun
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Autowired
    private ImageService imageService;

    @Override
    public List<Category> getAllCategory() {
        List<Category> categories = categoryDao.getAllCategory();
        for (Category category : categories) {
            Image topicImage = category.getTopicImage();
            Long id = topicImage.getId();
            topicImage = imageService.getImageById(id);
            category.setTopicImage(topicImage);
        }
        return categories;
    }
}
